﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using OUSMS.AppLogic.BusinessLogicLayer;
using OUSMS.Helpers;
using System.Web.ModelBinding;
using OUSMS.AppLogic.DataAccessLayer;
namespace OUSMS
{
    public partial class ForgetPassword : System.Web.UI.Page
    {
        protected void Page_Load(object sender, EventArgs e)
        {

        }

        protected void okButton_Click(object sender, EventArgs e)
        {
            UsersBLL userBLL = new UsersBLL();
            Users registeredUser = userBLL.GetUserByLoginName(loginNameTxtBox.Text.Trim());
            errorMsgLbl.Visible = true;
            if (registeredUser == null)
            {
                errorMsgLbl.Text = "您的输入的账号信息不正确，系统不存在该账号信息。";
            }
            else if (!registeredUser.Email.Equals(emailTxtBox.Text.Trim()))
            {
                errorMsgLbl.Text = "您的输入的账号信息不正确，系统不存在该账号信息。";
            }
            else
            {
                string emailBody = string.Format("{0}, 您好： 您在{1}提交了密码遗忘申请，系统查到您的注册用户名是{2}, 密码是{3}。如果非您本人操作，请您及时联系系统管理员。", registeredUser.Name, DateTime.Now.ToString("yyyy年MM月dd日 HH:mm"), registeredUser.LoginName, registeredUser.Password);
                Emailer.SendMail("国家开放大学科研提案系统注册信息", emailTxtBox.Text.Trim(), "libncepu@sina.com", emailBody);
                errorMsgLbl.Text = "您的账号信息已发送至您的邮箱，请您查收。";
            }
        }
    }
}